package com.cardone.platform.usercenter.controller;

import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;

import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cardone.context.Contexts;
import com.cardone.common.dto.PaginationDto;
import com.cardone.common.dto.ReturnDataDto;
import com.cardone.common.util.ReturnDataUtils;
import com.cardone.context.ContextHolder;
import com.cardone.platform.usercenter.dto.UserActivationDto;
import com.cardone.platform.usercenter.service.UserActivationService;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

/**
 * 用户激活
 *
 * @author yaohaitao
 */
@Deprecated
@Setter
@Slf4j
@RequestMapping("/usercenter/userActivation/")
@Controller
public class UserActivationController {

	/**
	 * 用户激活：删除
	 * 
	 * @param deleteUserActivation
	 *            用户激活对象
	 * @return 处理结果，json格式
	 */
	@Deprecated
	@RequestMapping(value = { "delete.json" }, method = RequestMethod.POST)
	@ResponseBody
  public Callable<ReturnDataDto<String>> deleteJson(final UserActivationDto deleteUserActivation) {
		return new Callable<ReturnDataDto<String>>() {
			public ReturnDataDto<String> call() throws Exception {
				try {
					ContextHolder.getBean(UserActivationService.class).deleteByIds(deleteUserActivation);
					
					return ReturnDataUtils.newReturnData();
				} catch (final Exception e) {
					return ReturnDataUtils.newReturnData(e, log);
				}
			}
		};
	}

	/**
	 * 用户激活：编辑
	 * 
	 * @param findUserActivation
	 *            用户激活对象
	 * @return 实体对象集，json格式
	 */
	@Deprecated
	@RequestMapping(value = { "findById.json" })
	@ResponseBody
	public Callable<ReturnDataDto<UserActivationDto>> findByIdJson(final UserActivationDto findUserActivation, final Model model) {
		return new Callable<ReturnDataDto<UserActivationDto>>() {
			@Override
			public ReturnDataDto<UserActivationDto> call() throws Exception {
				try {
					final UserActivationDto userActivation = ContextHolder.getBean(UserActivationService.class).findById(UserActivationDto.class, findUserActivation);

					return ReturnDataUtils.newReturnData(userActivation);
				} catch (final Exception e) {
					return ReturnDataUtils.newReturnData(e, UserActivationController.log);
				}
			}
		};
	}

	/**
	 * 用户激活：分页查询
	 * 
	 * @param paginationUserActivation
	 *            用户激活对象
	 * @return 分页，json格式
	 */
	@Deprecated
	@RequestMapping(value = { "paginationByLikeCode.json" })
	@ResponseBody
  public Callable<ReturnDataDto<PaginationDto<UserActivationDto>>> paginationByLikeCodeJson(final UserActivationDto paginationUserActivation) {
		return new Callable<ReturnDataDto<PaginationDto<UserActivationDto>>>() {
			public ReturnDataDto<PaginationDto<UserActivationDto>> call() throws Exception {
				try {
					final PaginationDto<UserActivationDto> userActivationPagination = ContextHolder.getBean(UserActivationService.class).paginationByLikeCode(UserActivationDto.class, paginationUserActivation);
				
					return ReturnDataUtils.newReturnData(userActivationPagination);
				} catch (final Exception e) {
					return ReturnDataUtils.newReturnData(e, log);
				}
			}
		};
	}

	/**
	 * 用户激活：分页查询
	 * 
	 * @param paginationUserActivation
	 *            用户激活对象
	 * @param model
	 *            上下文映射
	 */
	@Deprecated
	@RequestMapping(value = { "pagination.html" })
  public void paginationHtml(final UserActivationDto paginationUserActivation, final Model model) {
		final PaginationDto<UserActivationDto> userActivationPagination = ContextHolder.getBean(UserActivationService.class).paginationByLikeCode(UserActivationDto.class, paginationUserActivation);
		
		model.addAttribute("userActivationPagination", userActivationPagination);
	}
	
	/**
	 * 用户激活：分页查询
	 * 
	 * @param findUserActivation
	 *            用户激活对象
	 * @param model
	 *            上下文映射
	 */
	@Deprecated
	@RequestMapping(value = { "edit.html" })
  public void editHtml(final UserActivationDto findUserActivation, final Model model) {
		final UserActivationDto userActivation = ContextHolder.getBean(UserActivationService.class).findById(UserActivationDto.class, findUserActivation);
		
		model.addAttribute("userActivation", userActivation);
	}

	/**
	 * 用户激活：查询
	 * 
	 * @param findListUserActivation
	 *            用户激活对象
	 * @return 用户激活对象集合，json格式
	 */
	@Deprecated
	@RequestMapping(value = { "findListByLikeCode.json" })
	@ResponseBody
  	public Callable<ReturnDataDto<List<UserActivationDto>>> findListByLikeCodeJson(final UserActivationDto findListUserActivation) {
		return new Callable<ReturnDataDto<List<UserActivationDto>>>() {
			public ReturnDataDto<List<UserActivationDto>> call() throws Exception {
				try {
					final List<UserActivationDto> userActivationList = ContextHolder.getBean(UserActivationService.class).findListByLikeCode(UserActivationDto.class, findListUserActivation);
				
					return ReturnDataUtils.newReturnData(userActivationList);
				} catch (final Exception e) {
					return ReturnDataUtils.newReturnData(e, log);
				}
			}
		};
	}

	/**
	 * 用户激活：保存
	 * 
	 * @param saveUserActivation
	 *            用户激活对象
	 * @return 处理结果，json格式
	 */
	@Deprecated
	@RequestMapping(value = { "save.json" })
	@ResponseBody
  public Callable<ReturnDataDto<String>> saveJson(final UserActivationDto saveUserActivation) {
		return new Callable<ReturnDataDto<String>>() {
			public ReturnDataDto<String> call() throws Exception {
				try {
					ContextHolder.getBean(UserActivationService.class).saveByIdOrCode(UserActivationDto.class, saveUserActivation);
					
					return ReturnDataUtils.newReturnData();
				} catch (final Exception e) {
					return ReturnDataUtils.newReturnData(e, log);
				}
			}
		};
	}
}
